﻿<UserControl x:Class="Soat.HappyNet.Silverlight.Modules.Production.Views.ProductItemView"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:windowControls="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls"             
    xmlns:regions="clr-namespace:Microsoft.Practices.Composite.Presentation.Regions;assembly=Microsoft.Practices.Composite.Presentation"
    xmlns:cal="clr-namespace:Microsoft.Practices.Composite.Presentation.Commands;assembly=Microsoft.Practices.Composite.Presentation"
    xmlns:controls="clr-namespace:Soat.HappyNet.Silverlight.Library.Controls;assembly=Soat.HappyNet.Silverlight.Library"
    xmlns:behavior="clr-namespace:Soat.HappyNet.Silverlight.Library.Behaviors;assembly=Soat.HappyNet.Silverlight.Library"
    xmlns:i="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity"
    xmlns:triggers="clr-namespace:Soat.HappyNet.Silverlight.Library.Behaviors.Triggers;assembly=Soat.HappyNet.Silverlight.Library"
    xmlns:actions="clr-namespace:Soat.HappyNet.Silverlight.Library.Behaviors.Actions;assembly=Soat.HappyNet.Silverlight.Library"
    xmlns:imgtools="clr-namespace:ImageTools.Controls;assembly=ImageTools.Controls">
    <Grid x:Name="LayoutRoot">
        <VisualStateManager.VisualStateGroups>
            <VisualStateGroup x:Name="CommonStates">
                <VisualStateGroup.Transitions>
                    <VisualTransition GeneratedDuration="00:00:00.4000000" To="MouseOver"/>
                    <VisualTransition From="MouseOver" GeneratedDuration="00:00:00.4000000"/>
                </VisualStateGroup.Transitions>
                <VisualState x:Name="Normal"/>
                <VisualState x:Name="MouseOver">
                    <Storyboard>
                        <DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Duration="00:00:00.0010000" 
                                                       Storyboard.TargetName="RectangleOver" Storyboard.TargetProperty="(UIElement.Opacity)">
                            <SplineDoubleKeyFrame KeyTime="00:00:00" Value="0.8"/>
                        </DoubleAnimationUsingKeyFrames>
                    </Storyboard>
                </VisualState>
            </VisualStateGroup>
        </VisualStateManager.VisualStateGroups>

        <i:Interaction.Behaviors>
            <behavior:HoverBehavior HoverVisualStateName="MouseOver" />
        </i:Interaction.Behaviors>
        
        <i:Interaction.Triggers>
            <i:EventTrigger EventName="MouseLeftButtonDown">
                <actions:TrackEventAction Action="Click" Category="Shopping" Label="{Binding Name}"/>
                <actions:ExecuteCommandAction Command="{Binding SelectProductCommand}"/>
            </i:EventTrigger>
        </i:Interaction.Triggers>

        <Grid Width="150" Height="150"
              Margin="8"
              Cursor="Hand">
            <ToolTipService.ToolTip>
                <ToolTip Style="{StaticResource ToolTipStyle}" 
                         Content="{Binding Path=Strings.PRODUCTION_ViewDetail, Source={StaticResource LocalizedStrings}}" />
            </ToolTipService.ToolTip>
            
            <Border BorderBrush="White" 
                    BorderThickness="2"
                    CornerRadius="6,0,0,0"
                    Background="White">
                <Border.Effect>
                    <DropShadowEffect ShadowDepth="0" Direction="310" BlurRadius="10"/>
                </Border.Effect>
            </Border>
            <Grid Margin="2">
                <Grid.RowDefinitions>
                    <RowDefinition Height="Auto"/>
                    <RowDefinition Height="Auto"/>
                    <RowDefinition />
                </Grid.RowDefinitions>
                
                <TextBlock x:Name="ProductTitle" 
					       Text="{Binding Name}"
					       HorizontalAlignment="Center" 
					       TextAlignment="Center"
                           TextWrapping="Wrap"/>
                
                <StackPanel Orientation="Horizontal"
                            Grid.Row="1"
                            HorizontalAlignment="Center">
                    <TextBlock Text="{Binding Price, Converter={StaticResource FormatConverter}, ConverterParameter='{0:0.00}'}"
                               Margin="0,0,5,0"/>
                </StackPanel>

                <Grid Grid.Row="2">
                    <Border Margin="10"
                            CornerRadius="6,0,0,0"
                            BorderBrush="{StaticResource DefaultBorderBrush}"
                            BorderThickness="2"
                            HorizontalAlignment="Center"
                            VerticalAlignment="Center">
                        <imgtools:AnimatedImage 
                            Stretch="Uniform"
                            x:Name="ProductImage">
                            <i:Interaction.Behaviors>
                                <behavior:ClippingBehavior CornerRadius="6,0,0,0" />
                            </i:Interaction.Behaviors>
                        </imgtools:AnimatedImage>
                    </Border>
                    <Grid>
                        <i:Interaction.Behaviors>
                            <!-- Affiche si on n'a pas d'erreur -->
                            <behavior:NullValueVisibilityBehavior
                                Negate="True"
                                ValueBinding="{Binding ThumbNailPhoto}" />
                            <!-- N'affiche pas durant le chargement -->
                            <behavior:BoolValueVisibilityBehavior
                                Negate="True"
                                ValueBinding="{Binding IsLoading}" />
                        </i:Interaction.Behaviors>
                        <Rectangle RadiusX="3" RadiusY="3"
                                   Width="50"
                                   Height="50"
                                   HorizontalAlignment="Center"
                                   VerticalAlignment="Center"
                                   Fill="#20FF0000"/>
                        <TextBlock Text="X"
                                   FontWeight="Bold"
                                   FontSize="15"
                                   Foreground="#FFFF3333"
                                   HorizontalAlignment="Center"
                                   VerticalAlignment="Center"
                                   Style="{StaticResource LabelStyle}"/>
                    </Grid>
                </Grid>
            </Grid>

            <Border x:Name="RectangleOver"
                    BorderBrush="{StaticResource TitleHoverHeaderBrush}"
                    BorderThickness="2"
                    CornerRadius="6,0,0,0"
                    Opacity="0" 
                    IsHitTestVisible="False"/>
            
            <controls:Loading IsLoading="{Binding IsLoading}"
                                  HorizontalAlignment="Center"
                                  VerticalAlignment="Center"
                                  Width="40" Height="40" />
        </Grid>
    </Grid>
</UserControl>
    